//
//  YBFeedbackViewController.m
//  GoodBuy
//
//  Created by Cyber on 15/5/18.
//  Copyright (c) 2015年 GoodBuy. All rights reserved.
//

#import "YBFeedbackViewController.h"

@interface YBFeedbackViewController ()

@end

@implementation YBFeedbackViewController

-(void)dealloc {
    [_detail release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIControl *backGroundControl = [[UIControl alloc] initWithFrame:
                                    CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    backGroundControl.backgroundColor = [UIColor clearColor];
    [backGroundControl addTarget:self
                          action:@selector(backgroundTab)
                forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backGroundControl];
    
    
    // Do any additional setup after loading the view.
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 50)];
    label1.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 30+64);
    label1.text = @"我们十分期待您的意见!";
    label1.font = [UIFont systemFontOfSize:25];
    label1.textAlignment = UITextAlignmentCenter;
    [self.view addSubview:label1];
    
    self.detail = [[UITextView alloc]initWithFrame:CGRectMake(20, label1.frame.origin.y + 70, [UIScreen mainScreen].bounds.size.width-40, 100)];
//    _detail.backgroundColor = [UIColor grayColor];
    _detail.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:_detail];
    _detail.layer.borderWidth = 2.0;
    _detail.layer.cornerRadius = 20;
    [_detail.layer setBorderColor:[UIColor grayColor].CGColor];

    [_detail release];
    
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(_detail.frame.origin.x, _detail.frame.origin.y + 95, [UIScreen mainScreen].bounds.size.width - 40, 60)];
    label2.text = @"请留下您的联系方式:(微信号,QQ号或者手机号.会有客服联系您)";
    label2.numberOfLines = 0;
    label2.textColor = [UIColor blackColor];
    [self.view addSubview:label2];
    [label2 release];
    
    
    
    self.number = [[UITextView alloc]initWithFrame:CGRectMake(20, _detail.frame.origin.y + 150, [UIScreen mainScreen].bounds.size.width-40, 50)];
    [self.view addSubview:_number];
    _number.font = [UIFont systemFontOfSize:20];
    _number.layer.borderWidth = 2.0;
    _number.layer.cornerRadius = 20;
    [_number.layer setBorderColor:[UIColor grayColor].CGColor];
    
    [_number release];
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    _button.frame = CGRectMake(100, 400, 80, 60);
    _button.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, _number.frame.origin.y +    _number.frame.size.height + 90);
    //
    [self.view addSubview:_button];
    [_button setTitle:@"发出" forState:UIControlStateNormal];
    _button.titleLabel.font = [UIFont systemFontOfSize:24];
    _button.layer.masksToBounds = YES;
    _button.layer.cornerRadius = 20;

    _button.backgroundColor = [UIColor redColor];
    [_button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.feedback = [UMFeedback sharedInstance];
    self.feedback.delegate = self;
    [self.feedback get];

    
    
}
- (void)buttonAction {
    
    if ([_number.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"请留下您的联系方式" message:@"如果您不想留下任何信息,请再联系方式输入框中任意输入.打扰了." delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
    } else {
        NSString *str = [NSString stringWithFormat:@"意见:%@ ++++ 联系方式:%@ ", _detail.text, _number.text];
        
        NSDictionary *dic = [[NSDictionary alloc]initWithObjects:[NSArray arrayWithObject:str] forKeys:[NSArray arrayWithObject:@"content"]];
        [self.feedback post:dic];
        
        [self.navigationController popViewControllerAnimated:YES];
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"么么哒!" message:@"谢谢您的宝贵意见.您的意见我们会倍加珍惜.期待您在下一个版本中看到我们的进步." delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
    }
    
}

- (void)backgroundTab
{
    [_detail resignFirstResponder];
    [_number resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
